﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Pavilion.GameTools;

namespace Pavilion.Locks
{
    public class PhysicalStateLock : ILock
    {
        public PhysicalState PhysicalState { get; set; }

        public void Deserialize(XElement lockElement, string resourceName)
        {
            PhysicalState = (PhysicalState)Enum.Parse(typeof(PhysicalState), lockElement.Attribute("PhysicalState").Value);
        }

        public XElement Serialize()
        {
            XElement lockElement = new XElement("Lock");

            lockElement.Add(new XAttribute("PhysicalState", PhysicalState));

            return lockElement;
        }

        public LockMonitorBase CreateLockMonitor(GameItem gameItem)
        {
            PolygonPhysicalData polygonData = gameItem.ObtainTool<PhysicalTypeTool>().PolygonData;
            return new LockPredicateMonitor(polygonData, () => polygonData.PhysicalState == PhysicalState);
        }

        public override string ToString()
        {
            return this.GetType().Name;
        }
        }
    }

